// 示例 1:

// 输入: nums = [1, 2, 3, 4]
// 输出: [24, 12, 8, 6]
// 示例 2:

// 输入: nums = [-1, 1, 0, -3, 3]
// 输出: [0, 0, 9, 0, 0]

nums = [1, 2, 3, 4]

var productExceptSelf = function (nums) {
    let len = nums.length
    let left = new Array(len).fill(1)
    let right = new Array(len).fill(1)
    let result = []

    for (let i = 1; i < len; i++) {
        left[i] = left[i - 1] * nums[i - 1]
    }
    for (let i = len - 2; i >= 0; i--) {
        right[i] = right[i + 1] * nums[i + 1]
    }
    for (let i = 0; i < len; i++) {
        result.push(left[i] * right[i])
    }
    return result
}

console.log(productExceptSelf(nums));
